package com.suixun.controller;

import com.suixun.controller.base.BaseController;
import com.suixun.controller.vo.CooperationPartnerVo;
import com.suixun.controller.vo.CooperationPolicyVo;
import com.suixun.domain.CooperationPartnerDisplay;
import com.suixun.domain.CooperationPolicy;
import com.suixun.service.BannerService;
import com.suixun.service.CooperationPartnerDisplayService;
import com.suixun.service.CooperationPolicyService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

/**
 * 生态圈
 */
@Controller
@RequestMapping("/ecosphere")
public class EcosphereController extends BaseController {

    @Resource
    private CooperationPolicyService cooperationPolicyService;
    @Resource
    private CooperationPartnerDisplayService cooperationPartnerDisplayService;
    @Resource
    private BannerService bannerService;

    /**
     * 分页
     * @param page1 合作政策当前页
     * @param size1 合作政策单页总条数
     * @param page2 合作伙伴当前页
     * @param size2 合作伙伴单页总条数
     * @param model
     * @return
     */
    @GetMapping("/index/{page1}/{size1}/{page2}/{size2}")
    public String index(@PathVariable Integer page1, @PathVariable Integer size1, @PathVariable Integer page2, @PathVariable Integer size2, Model model) {
        model.addAttribute("bannerList", bannerService.listBanners(null, 2));
        model.addAttribute("policyPage", cooperationPolicyService.pageExclusionContent(page1, size1, null, 1));
        model.addAttribute("partnerPage", cooperationPartnerDisplayService.pageOnlyIncludeImgUrl(page2, size2));
        return "caseShow";
    }


    /**
     * 合作政策详情
     * @param id
     * @param model
     * @return
     * @throws UnsupportedEncodingException
     */
    @GetMapping("/getPolicy/{id}")
    public String getPolicy(@PathVariable Integer id, Model model) throws UnsupportedEncodingException {
        CooperationPolicy cooperationPolicy = cooperationPolicyService.getById(id);
        if (cooperationPolicy != null) {
            get(new CooperationPolicyVo(), cooperationPolicy, model);
        }
        return "single2";
    }

    /**
     * 合作伙伴详情
     * @param id
     * @param model
     * @return
     * @throws UnsupportedEncodingException
     */
    @GetMapping("/getPartner/{id}")
    public String getPartner(@PathVariable Integer id, Model model) throws UnsupportedEncodingException {
        CooperationPartnerDisplay cooperationPartnerDisplay = cooperationPartnerDisplayService.getById(id);
        if (cooperationPartnerDisplay != null) {
            get(new CooperationPartnerVo(), cooperationPartnerDisplay, model);
        }
        return "single2";
    }

}
